//
//  KMeetingRequestDAO.m
//  KutulusLaw
//
//  Created by Mahmood1 on 12/17/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "KMeetingRequestDAO.h"
@implementation KMeetingRequestDAO

+ (BOOL)meetingRequest:(KMeetingRequestCommandDTO *)meetingRequest block:(void (^)(NSInteger isSuccess, NSError *))block {
	if (meetingRequest) {
		
		MyApiClient *client = [MyApiClient sharedClient];
		NSMutableDictionary *parameters = [meetingRequest dictionary];
		NSLog(@"parameter of case api: %@", parameters);
		
		[client postPath:@"" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
			if (responseObject) {
				responseObject = [responseObject objectFromJSONData];
				NSLog(@"Response data from case api: %@", responseObject);
				NSString *status = [[responseObject objectForKey:@"status"] uppercaseString];
				if ([status isEqualToString:@"OK"]) {
					block (OK, nil);
					return;
				} else if ([status isEqualToString:@"NOT_AUTHENTICATE"]) {
					block (NOT_AUTHENTICATE, nil);
					return;
				} else {
					block (NOT_VALID, nil);
					return;
				}
			}
			
			
			block(NOT_VALID, nil);
			
		} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
			block(NOT_VALID, error);
		}];
		
		return YES;
	} 
	
	return NO;
}

@end
